<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>余额宝详情_共富网_Gofull.com.cn</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>		
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
		<script type="text/javascript" src="/v3/js/showts.js"></script>
	</head>
<style>
</style>
	<body>
		<div id="wrap">
			<div class="product-o">
				<p>每个工作日 10:00、14:00、17:00 更新总额度 </p>
			</div>
			<div class="product-box">
				<ul class="pro-t">
					<li class="pro-amount">
						<p>总额度</p>
						<span>￥ ${productDetailMap.totalSumAll}</span>
					</li>
					<li class="pro-rate">
						<p>年化收益率</p>
						<span>${productDetailMap.yebAnnualRate }%</span>
					</li>
					<li class="pro-limit">
						<p>投资期限</p>
						<span>活期</span>
					</li>
				</ul>
				<div class="pro-expl">
					<div class="pro-remain">剩余金额 <em>￥${productDetailMap.remain}</em></div>
					<div class="pro-ratio-per">
						<div class="per" data-rel="${productDetailMap.schedules}">
								<div style="width: ${productDetailMap.schedules}%"></div>
						</div>
						<strong>当前进度${productDetailMap.schedules}%</strong>
					</div>
				</div>				
			</div>
			<ul class="pro-info">
					<li><p>起投金额</p><span>1,000元起，且以1,000元的倍数递增</span></li>
					<li><p>单户额度上限 </p><span>￥100,000 </span></li>
					<li><p>保障方式 </p><span><i class="icon-safe"></i>100% 本息保障</span></li>
					<li><p>产品说明</p><span onclick="location.href='/wchatProductDescription.do?pid=${productDetailMap.pid }&productType=1'"><i class="icon-next"></i></span></li>
					<li><p>投资记录</p><span onclick="location.href='/yebInvestRecord.do?pid=${productDetailMap.pid }'"><i class="icon-next"></i></span></li>
					<li><p>信息披露</p><span onclick="location.href='/getWchatInfoDisclosureByPid.do?pid=${productDetailMap.pid}&productType=1'"><i class="icon-next"></i></span></li>
			</ul>
			
			<div class="money-input">
				<div class="login_input inv_input">
				<div class="r_line">
				<i class="icon-calc" onclick="showDetalDIv()"></i>
				</div>
				<input type="hidden" id="realnameFlag" value="${session.user.isBindIdNo}">
				<div class="in_put"><input placeholder="请输入1000的整数倍数" id="inputAmount" name="inputAmount" maxlength="17" type="tel"></div>
				</div>
				<div class="box-bottom"><img src="/v3/images/box_icon.jpg"/></div>
			</div>
			<div class="Nxt-btn"><a href="javascript:invest();" id="investBt">确认购买</a></div>
		</div>
		
		<!-- 计算收益值开始 -->
		<section class="zhezhao" id="zhezhao" style="position:fixed;bottom:0"></section>
		<input type="hidden" name="ptype" id="ptype" value="yeb">
		<aside class="zhezhao_div" id="showDiv">
			<div class="zhe_div" id="zhe">
				<div class="topzh" id="topzh">
					<div class="topzh_zhezhao act" id="yeb" productCat="yeb">
						<p style="color:#fff">余额宝</p>
					</div>
					<div class="topzh_zhezhao" id="ylb" productCat="ylb">
						<p>月利宝</p>
					</div>
					<div class="topzh_zhezhao" id="jfb" productCat="jfb">
						<p>季发宝</p>
					</div>
					<div class="topzh_zhezhao" id="wyb" productCat="wyb">
						<p>稳盈宝</p>
					</div>
				</div>
				<section class="zhezhao_ct">
					<div class="zhezhao_top"></div>
					<div class="zhezhao_td">
						<p>预期收益</p>
						<span id="shouyi">1250.0元</span>
					</div>
					<div class="zhezhao_thd">
						<div class="zhezhao_thd_od">
							<div class="zhezhao_di">
								<p>买入金额</p>
							</div>
							<div class="zhezhao_dt">
								<input type="text" id="input_sal" value="10000">
								<p>元</p>
							</div>
						</div>
						<div id="ct">
							<nav style="display:block">
							<div class="zhezhao_thd_od">
								<div class="zhezhao_di">
									<p>买入天数</p>
								</div>
								<div class="zhezhao_dt">
									<input type="hidden" value="yeb" id="productCat" name="productCat"/>
									<input type="text" id="input_days" value="365" onblur="isNumber(this)" onchange="caluateProfit()">
									<p>天</p>
								</div>
							</div>
							</nav>
							<nav>
							<div class="zhezhao_thd_od">
								<div class="zhezhao_di">
									<p>买入天数</p>
								</div>
								
								<div class="zhezhao_dt">
									<div class="dv">
										<p>1个月</p>
									</div>
								</div>
							</div>
							</nav>
							<nav>
							<div class="zhezhao_thd_od">
								<div class = "zhezhao_di">
									<p>买入天数</p>
								</div>
								<div class="zhezhao_dt">
									<div class="dv">
										<p>3个月</p>
									</div>
								</div>
							</div>
							</nav>
							<nav>
								<div class="zhezhao_thd_od">
								<div class="zhezhao_di">
									<p>买入天数</p>
								</div>
								<div class="zhezhao_dt">
									<input type="text" id="input_days2" value="12" onblur="isNumber(this)" onchange="caluateProfit()">
									<p>个月</p>
								</div>
								</div>
							</nav>
						</div>
						<div class="zhezhao_thd_od" id="wyb-rate" style="display:none;">
							<div class="zhezhao_di">
								<p>年化利率</p>
							</div>
							<div class="zhezhao_dt">
								<input id="input_wybRate" value="12" type="text">
								<p>%</p>
							</div>
						</div>
						<div class="zhezhao_thd_od" id="wyb-repay" style="display:none;">
							<div class="zhezhao_di">
								<p>还款方式</p>
							</div>
							<div class="zhezhao_dt">
									<select name="" id="repayType">
										<option value="1">按月等额本息</option>
										<option value="2">按月还息到期还本</option>
										<option value="3">一次性还本付息</option>
									</select>
							</div>
						</div>

						<div class = "zhezhao_dv">
							<p>预期收益率:<b id="yuqi">${productDetailMap.yebAnnualRate }%</b></p>
						</div>
						<div>
							<input type="button" value="计算" class="calc_btn" id="sub" onclick="caluateAmount()"/>
							<input type="hidden" value="7" id="baseYield" name="baseYield"/>
						</div>
					</div>
				</section>
			</div>
			</aside> 
		<!-- 计算收益值结束 -->
		
		<jsp:include page="/include/v3/footer.jsp"></jsp:include>
	</body>
<script><!--
	    var lastptype="6";
	 	var lastproduct="6";
	 	var productCat=$("#ptype").val();
	 	var restMonthAmount=isNaN(parseFloat($("#restMonthAmount").val())) ? 0 : parseFloat($("#restMonthAmount").val());
	 	var flag=$("#flag").val();
		$(function (){
			var index;
			var id;
			var $div = $('nav');
			var $bt = $('.cln aside');
			var $ct = $('#ct nav');

			$('#topzh div').on('click',function (){
				index = $(this).index();
				$(this).addClass('topzh_zhezhao act').siblings().removeClass('act');
				$ct.eq(index).show().siblings().hide();
				$(this).find('p').css('color','#fff').parent().siblings().find('p').css('color','#a0a0a0');
				if(index==0){
					$("#yuqi").html("${productDetailMap.yebAnnualRate }%");
					$("#baseYield").val("${productDetailMap.yebAnnualRate }%");
					$("#productCat").val("yeb");
					$("#input_days").val("365");
					$("#wyb-rate").hide();
					$("#wyb-repay").hide();
					$(".zhezhao_dv").show();
				    caluateAmount();
				}else if(index==1){
					$("#yuqi").html("${ylbMap.productAnnualRate }%");
					$("#baseYield").val("${ylbMap.productAnnualRate }");
					$("#productCat").val("ylb");
					$("#input_days").val("1");
					$("#wyb-rate").hide();
					$("#wyb-repay").hide();
					$(".zhezhao_dv").show();
					caluateAmount();
				}else if(index==2){
					$("#yuqi").html("${jfbMap.productAnnualRate }%");
					$("#baseYield").val("${jfbMap.productAnnualRate }");
					$("#productCat").val("jfb");
					$("#input_days").val("3");
					$("#wyb-rate").hide();
					$("#wyb-repay").hide();
					$(".zhezhao_dv").show();
					caluateAmount();
				}
				else{
					$("#baseYield").val($("#input_wybRate").val());
					$("#productCat").val("wyb");
					$("#input_days").val($("#input_days2").val());
					$("#wyb-rate").show();
					$("#wyb-repay").show();
					$(".zhezhao_dv").hide();
					caluateAmount();
				}
			});
		
		});

		function showDetalDIv(){
		    $("#zhezhao").show();
			$("#showDiv").show();
			$("#zhe").show();
			if(productCat=="yeb"){
				$("#yuqi").html("${productDetailMap.yebAnnualRate }%");
				$("#baseYield").val("${productDetailMap.yebAnnualRate }");
				$("#input_days").val("365");
				showCss(1);
			}else if(productCat=="ylb"){
				$("#yuqi").html("${ylbMap.productAnnualRate }%");
				$("#baseYield").val("${ylbMap.productAnnualRate }");
				$("#input_days").val("1");
				showCss(2);
			}else if(productCat=="jfb"){
				$("#yuqi").html("${jfbMap.productAnnualRate }%");
				$("#baseYield").val("${jfbMap.productAnnualRate }");
				$("#input_days").val("3");
				showCss(3);
			}
			else{
				$("#baseYield").val($("#input_wybRate").val());
				$("#input_days").val($("#input_days2").val());
				showCss(4);
			}
			caluateAmount();
		}
		function showCss(index){
			var selector=".topzh div:nth-child("+index+")";
			var selectIndex="#ct nav:nth-child("+index+")";
			$(selector).addClass('topzh_zhezhao act').siblings().removeClass('act');
			$(selectIndex).show().siblings().hide();
			$(selector).find('p').css('color','#fff').parent().siblings().find('p').css('color','#a0a0a0');
		}
		function caluateAmount() {
			var repayType = $.trim($("#repayType").val());
			var productCat=$("#productCat").val();
			if(productCat=="wyb"){
				var input_days=$("#input_days2").val();
				var input_sal=$("#input_sal").val();
				var baseYield=$("#input_wybRate").val();
			}
			else{
			var input_days=$("#input_days").val();
			var input_sal=$("#input_sal").val();
			var baseYield=$("#baseYield").val();
			}
		    if(isNumber(input_days)&&isNumber(input_sal)){
		    	if(productCat=="ylb"){
			    	var shouyi=(input_sal*input_days*(parseFloat(baseYield))/100/12).toFixed(2);
				    $("#shouyi").html(shouyi);
				    }
			    else if(productCat=="jfb"){
			    	var shouyi=(input_sal*input_days*(parseFloat(baseYield))/100/12).toFixed(2);
				    $("#shouyi").html(shouyi);
				    }
			    else if(productCat=="yeb"){
			    	var shouyi=(input_sal*input_days*(parseFloat(baseYield))/100/365).toFixed(2);
			    	$("#shouyi").html(shouyi);
				}else{ 
					var shouyi = 0;
					if(repayType==1){
						shouyi = getPayByMonth(input_sal,(input_days/12),parseFloat(baseYield)/100).toFixed(2);
					}else{
						shouyi=(input_sal*input_days*(parseFloat(baseYield))/100/12).toFixed(2);
					}
			    	$("#shouyi").html(shouyi);
			    }
		    }
	   }
		//稳盈宝-等额本息
		function getPayByMonth(dke,ns,nll) {
	        var pay = 0;
	        var yll = nll / 12;
	        yg = (dke * yll * (Math.pow((1 + yll), ns * 12)))
	                / (Math.pow((1 + yll), ns * 12) - 1);
	        var zlx = (yg * 12 * ns - dke);
            
	        return zlx;
	    }
			
		/*function caluateProfit(){
		var productCat=$("#productCat").val();
		if(productCat=="yeb"){
		var url="/statistic/caluateProfit.html";
		var days=$("#input_days").val();
		  $.get(url,{"days":days},function (data){
				if(data!=null){
					$("#yuqi").html(data);
					$("#baseYield").val(data);	
					caluateAmount();
				}
			});
			 
			}
		} */
		

		//关闭弹出层
		$("#zhe2").click(function(){
		 	$("#zhezhao").hide();
			$("#showDiv").hide();
			$("#zhe").hide();
		});
		$("#zhezhao").click(function (){
			$("#zhezhao").hide();
			$("#showDiv").hide();
			$("#zhe").hide();
		});
		function isNumber(oNum) {  
	    if (!oNum)  
	        return false;  
	    var strP = /^\d+(\.\d+)?$/;  
	    if (!strP.test(oNum))  
	        return false;  
	    try {  
	        if (parseFloat(oNum) != oNum)  
	            return false;  
	    } catch (ex) {  
	        return false;  
	    }  
	    return true;  
	}
	--></script>

<script type="text/javascript">
var product = {
		aunualInterestRate : '${productDetailMap.productAnnualRate}',
		remain : '${productDetailMap.remain}',
		id : '${productDetailMap.pid}'
	};
var usavlesum = '${accmountStatisMap.usableSum}';
$(function(){
	/**
	var loanStatus = '300';
	if (loanStatus != "300") {
     window.location.href="/yuexitong/loanDetail.do?loanId=45185";
	}
	**/
  $('#agreeContract').click(function(){
    if ($('#agreeContract').attr("checked") == "checked") {
      $('#agreeContract').removeAttr("checked");
    } else {
      $('#agreeContract').attr("checked", "checked");
    }
  });
});
//刷新验证码
/**function coderefresh() {
    var verifyCode = $("#verifyCodeImg");
    var now = new Date();
    verifyCode.attr("src",'I4008lOve893gOfUll983/imageCode.do?pageId=yebWchatInvest&d=' + now.getTime());
}**/
//投资检查
function investCheck() {
	var errorTip = $('#errorTip');
	var cash = Number(usavlesum);
    var investAmountInput = $("#inputAmount");
    var investAmount = investAmountInput.val();
    var maxInvestAmount = Number(product.remain);
    var investableCash = Number(usavlesum);
    var availableCouponAmount = Number($("#availableCouponAmount").html());
    if(isNaN(investAmount*1) || investAmount*1<=0){
    	showAlert('请输入正确的金额');
        return false;
    }
    if(investAmount%1000 != 0){
    	showAlert('投资额只能为1000的整数倍');
        return false;
    }
    if(investAmount > maxInvestAmount){
    	showAlert('投资额不能大于剩余可投额度');
        return false;
    }
    /**
    if(investAmount > 10000.00){
        Util.arrowPrompt($("#investableAmount"),'投资额不能大于单笔最高可投额度', 'err');
        return false;
    }
    **/
    
    if(investAmount > cash){
    	showAlert('您的余额不足，请充值');
        return false;
    }
    /**
    var useCoupon = $("#useCoupon");
    if(useCoupon.hasClass("selected")){
        if(investAmount - availableCouponAmount > cash){
            errorTip.html('您的余额不足，请充值');
            return false;
        }
    }else{
        if(investAmount - availableCouponAmount > cash){
            errorTip.html('您的余额不足，请充值');
            return false;
        }else if(investAmount > cash && investAmount <= (cash + availableCouponAmount)){
            errorTip.html('您的余额不足，可使用红包');
            return false;
        }
    }**/
    if(investAmount < 1000.00){
        showAlert('最小投资金额为'+1000.00);
        return false;
    }
	/**
    var verifyCodeInput = $("#authCode");
    var verifyCode = verifyCodeInput.val();
    if(verifyCode == ''){
        errorTip.html('请输入验证码');
        return false;
    }

    if($('#agreeContract').attr("checked") != "checked"){
        errorTip.html('您尚未同意相关投资协议');
        return;
     }**/
     
  //未实名认证，不能投资
	if($("#realnameFlag").val() == "0"){
		showAlert('未实名认证，不能投资');
        $('#realNameBt').show();
		$('#investBt').hide();
        return false;
    }
    
    return true;
}
//投资月息通或新手标
function invest() {
  if(!investCheck()){
    return;
  };
  var errorTip = $('#errorTip');
  var investAmount = $("#inputAmount").val();
  var verifyCode = $("#authCode").val();
  
  var param = {};
  param['paramMap.pid'] = product.id;
  param["paramMap.pageId"] = "yebWchatInvest";
  param["paramMap.code"] = verifyCode;
  param['paramMap.amount'] = investAmount;
  
  $.ajax({
          dataType: 'json',
          url: "/yebFinanceInvest.do",
          data: param,
          type: 'POST',
          beforeSend: function() {
              $("#investBt").attr("href","javascript:;").html("正在加入...").addClass("gbtn-disabled");
          },
          success: function(data) {
              if(data.result == 'success'){
                  //window.location.href="/wchatYebDetail.do?pid="+${productDetailMap.pid};
            	  $("#inputAmount").val("");
            	  window.location.href="/investSuccess.do";
              }else{
                  if(data.msg == '验证码错误'){
                      showAlert("验证码错误");
                      $("#investBt").attr("href","javascript:invest();").html("我要购买").removeClass("gbtn-disabled");
                  }else{
                	  showAlert(data.msg);
                      $("#investBt").attr("href","javascript:invest();").html("我要购买").removeClass("gbtn-disabled");
                  }
              }
          },
          error: function() {
        	  showAlert("投资失败，请刷新页面或稍后再试");
          }
      });

}
//计算可使用红包金额
function calAvailableCouponAmount(){
    var inputAmount = Number($("#inputAmount").val());
    var availableCouponAmount = $(".availableCouponAmount");
    for(var i=0,len=availableCouponAmount.length;i<len;i++){
        var leftAmount = Number($(availableCouponAmount[i]).attr("leftamount"));
        var usageType = Number($(availableCouponAmount[i]).attr("usagetype"));
        var discountRatio = Number($(availableCouponAmount[i]).attr("discountratio"));
        var discountAmount = Number($(availableCouponAmount[i]).attr("discountamount"));
        var couponId = $(availableCouponAmount[i]).attr("couponid");
        var typeTitle = $(availableCouponAmount[i]).attr("typetitle");
        var useCoupon=$('#coupon' + couponId);
        if(usageType == 800){
            var availableAmount = inputAmount*discountRatio;
            if(availableAmount > leftAmount){
              availableAmount = leftAmount;
            }
        }else{
            var availableAmount = leftAmount > discountAmount ? discountAmount : leftAmount;
        }
       
        if(isNaN(availableAmount)){
            availableAmount = 0;
        }
        useCoupon.html(typeTitle + "￥" + availableAmount.toFixed(2));
        useCoupon.attr("useCouponAmount", availableAmount.toFixed(2));
    }
}
</script>

</html>
